package com.xishu.response;

import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.ThreadContext;

public class ResponseData {

    private int status;

    private String msg;

    private String msgEn;

    private Object data;

    private long size = 0;

    private long pageSize = 0;

    private long realSize;

    public ResponseData(Object o) {
        this.data = o;
        this.status = 0;
    }

    public ResponseData() {
        this.data = "";
    }

    public ResponseData(ResponseStatus responseStatus) {
        this.status = responseStatus.getStatus();
        String msg = ThreadContext.get("verify.msg");
        String msg_en = ThreadContext.get("verify.msg.en");
        if (msg != null) {
            this.msg = msg;
            this.msgEn = msg_en;
            ThreadContext.remove("verify.msg");
            ThreadContext.remove("verify.msg.en");
        } else {
            this.msg = responseStatus.getMsg();
            this.msgEn = responseStatus.getMsg_en();
        }

    }

    public static String getSuccessData() {
        return JSONObject.fromObject(new ResponseData()).toString();
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public long getSize() {
        return size;
    }

    public ResponseData setSize(long size) {
        this.size = size;
        return this;
    }

    public long getPageSize() {
        return pageSize;
    }

    public ResponseData setPageSize(long pageSize) {
        this.pageSize = pageSize;
        return this;
    }

    public static ResponseData emptyResponse() {
        return new ResponseData();
    }

    @Override
    public String toString() {
        return JSONObject.fromObject(this).toString();
    }

    public long getRealSize() {
        return realSize;
    }

    public void setRealSize(long realSize) {
        this.realSize = realSize;
    }

    public String getMsgEn() {
        return msgEn;
    }

    public void setMsgEn(String msgEn) {
        this.msgEn = msgEn;
    }
}
